'use strict';

angular.module('app')
    .controller('LoginCtrl', [ '$scope', '$location', 'svcMain', 'svcState', 'server', function ($scope, $location, svcMain, svcState, server) {

    $scope.$emit('EVENT.LOGGED_OUT');

    $scope.loginWithGoogle = function() {
        $("#googleLoginForm").attr("action", server + '/google-login');

        var path = $location.absUrl().substring(0, $location.absUrl().length - $location.path().length) + '/';
        $('<input/>').attr({ type:'hidden', name:'onSuccessUrl', value: path + '/' }).appendTo('form');
        $('<input/>',{ type:'hidden', name:'onErrorUrl', value: path + '/error' }).appendTo('form');
        svcState.setLoginUser($scope.googleLoginId);
    }

    }]);

